

import 'package:flutter/material.dart';
import 'package:net_store/Entities/Product.dart';
import 'package:photo_view/photo_view.dart';

class ProductDetailsPage extends StatefulWidget {
  Product product;

  ProductDetailsPage(this.product);
  @override
  State<StatefulWidget> createState() => _ProductDetailsPageState();
}

class _ProductDetailsPageState extends State<ProductDetailsPage> {
  String currentImageUrl;

  @override
  void initState() {
    currentImageUrl = widget.product.images.first;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Directionality(
      textDirection: TextDirection.rtl,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Color(0xffFF3A09),
          centerTitle: true,
          title: Text(widget.product.name),
        ),
        body: Column(
          children: <Widget>[
            Container(
              height: 250.0,
              child: Card(
                child: Center(
                  child: Hero(
                      tag: widget.product.guid,
                      child: FlatButton(
                        child: Image.network(currentImageUrl),
                        onPressed: (){
                          Navigator.of(context).push(MaterialPageRoute(builder: (context) => GestureDetector(
                            child: PhotoView(
                              imageProvider: NetworkImage(currentImageUrl),
                              heroTag: widget.product.guid,
                            ),
                            onTap: (){
                              Navigator.of(context).pop();
                            },
                          )));
                        },
                      )
                  ),
                ),
              ),
            ),
            SizedBox(height: 5.0,),
            SizedBox(
              height: 50.0,
              child: ListView(
                scrollDirection: Axis.horizontal,
                children: widget.product.images.map((imageUrl){
                  return InkWell(
                    child: Container(
                      width: 80.0,
                      padding: EdgeInsets.symmetric(vertical: 5.0),
                      child: Image.network(imageUrl),
                    ),
                    onTap: (){
                      setState(() {
                        currentImageUrl = imageUrl;
                      });
                    },
                  );
                }).toList(),
              ),
            ),
            SizedBox(height: 10.0,),
            Card(
              child: Padding(
                padding: EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0, bottom: 10.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Expanded(child: Text(widget.product.name, style: TextStyle(fontSize: 20.0),),),
                        Text(widget.product.exportprice.toString(), style: TextStyle(fontSize: 20.0, color: Colors.red))
                      ],
                    ),
                    SizedBox(height: 5.0,),
                    Text(widget.product.describe)
                  ],
                ),
              ),
            )
          ],
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add_shopping_cart),
          onPressed: (){},
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      ),
    );
  }
}

